//
//  IWTabBarController.m
//  SINA
//
//  Created by 王相超 on 16/3/28.
//  Copyright © 2016年 chuanzhi. All rights reserved.
//

#import "IWTabBarController.h"
#import "IWTabBar.h"
#import "IWHomeViewController.h"
#import "IWNavigationController.h"
#import "IWDiscoveryController.h"

@interface IWTabBarController ()<IWTabBarDelegate>

@end

@implementation IWTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    IWTabBar *tabbar = [IWTabBar new];
    
    tabbar.delegate = self;
    
    [self setValue:tabbar forKey:@"tabBar"];
    
    IWHomeViewController *home = [IWHomeViewController new];
    [self addChildController:home imageName:@"tabbar_home" title:@"首页"];
    
    UITableViewController *message = [UITableViewController new];
    [self addChildController:message imageName:@"tabbar_message_center" title:@"消息"];
    
    IWDiscoveryController *discover = [IWDiscoveryController new];
    [self addChildController:discover imageName:@"tabbar_discover" title:@"发现"];
    
    UITableViewController *me = [UITableViewController new];
    [self addChildController:me imageName:@"tabbar_profile" title:@"我"];
    
}


//添加子控制器
-(void)addChildController:(UIViewController *)childController imageName:(NSString *)imageName title:(NSString *)title{
    
    //图片
    childController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //标题
    childController.title = title;
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [childController.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    
    IWNavigationController *nav = [[IWNavigationController alloc] initWithRootViewController:childController];
    
    [self addChildViewController:nav];
}


-(void)taBar:(IWTabBar *)tabBar didSelectedButton:(UIButton *)plusBtn{
    
    
    
    
}


@end
